<template>
    <div class="ele-body">
      <el-card shadow="never">
        <!-- 搜索表单 -->
        <el-form
          :model="where"
          label-width="77px"
          class="ele-form-search"
          @keyup.enter.native="reload"
          @submit.native.prevent>
          <el-row :gutter="15">
            <el-col :lg="5" :md="12">
              <el-form-item label="客户编码:">
                <el-input
                  clearable
                  v-model="where.danwNo"
                  placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :lg="5" :md="12">
              <el-form-item label="客户名称:">
                <el-input
                  clearable
                  v-model="where.danwName"
                  placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :md="5" :sm="12">
            <el-form-item label="起始日期:">
                <el-date-picker v-model="where.riqiBegin" type="date" format='yyyy-MM-dd' value-format='yyyy-MM-dd' placeholder="选择日期" clearable class="ele-fluid"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :md="5" :sm="12">
            <el-form-item label="结束日期:">
                <el-date-picker v-model="where.riqiEnd" type="date" format='yyyy-MM-dd' value-format='yyyy-MM-dd' placeholder="选择日期" clearable class="ele-fluid"></el-date-picker>
            </el-form-item>
          </el-col>
            <el-col :lg="4" :md="12">
              <div class="ele-form-actions">
                <el-button
                  type="primary"
                  icon="el-icon-search"
                  class="ele-btn-icon"
                  @click="reload">查询
                </el-button>
                <el-button @click="reset">重置</el-button>
              </div>
            </el-col>
          </el-row>
        </el-form>
        <!-- 数据表格 -->
        <ele-pro-table
          ref="table"
          :where="where"
          :datasource="url"
          :tableSize="mini"
          :columns="columns"
          :selection.sync="selection"
          height="calc(100vh - 270px)">
          <!-- 表头工具栏 -->
          <template slot="toolbar" v-if="false">
            <el-button
              @click="openEdit(null)"
              type="primary"
              icon="el-icon-plus"
              class="ele-btn-icon"
              size="small"
              v-if="permission.includes('sys:member:add')">添加
            </el-button>
            <el-button
              @click="removeBatch"
              type="danger"
              icon="el-icon-delete"
              class="ele-btn-icon"
              size="small"
              v-if="permission.includes('sys:member:dall')">删除
            </el-button>
          </template>
          <!-- 状态列 -->
          <template slot="status" slot-scope="{row}">
            <el-switch
              v-model="row.status"
              @change="editStatus(row)"
              :active-value="1"
              :inactive-value="2"/>
          </template>
          <!-- 操作列 -->
          <template slot="action" slot-scope="{row}" v-if="false">
            <el-link
              type="primary"
              :underline="false"
              icon="el-icon-edit"
              @click="openEdit(row)"
              v-if="permission.includes('sys:member:edit')">修改
            </el-link>
            <el-popconfirm
              class="ele-action"
              title="确定要删除此会员吗？"
              @confirm="remove(row)">
              <el-link
                type="danger"
                slot="reference"
                :underline="false"
                icon="el-icon-delete"
                v-if="permission.includes('sys:member:delete')">删除
              </el-link>
            </el-popconfirm>
          </template>
        </ele-pro-table>
      </el-card>
    </div>
  </template>

  <script>
  import { mapGetters } from "vuex";

  export default {
    name: 'Document',
    computed: {
      ...mapGetters(["permission"]),
    },
    data() {
      return {
        // 表格数据接口
        url: '/c37infjcdwzl/index',
        // 表格列配置
        columns: [
          {
            columnKey: 'selection',
            type: 'selection',
            width: 45,
            align: 'center',
            fixed: "left"
          },
          {
            prop: 'liusNo',
            label: '流水号',
            width: 100,
            align: 'center',
            showOverflowTooltip: true,
            fixed: "left"
          },
          {
            prop: 'danwNo',
            label: '客户编码',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110,
          },
          {
            prop: 'danwName',
            label: '客户名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 200,
          },
          {
            prop: 'beactive',
            label: '是否活动',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 80
          },
          {
            prop: 'gengxTime',
            label: '更新时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150,
          },
          {
            prop: 'lianxStaff',
            label: '联系人',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 60,
            slot: 'gender'
          },
          {
            prop: 'dizPhone',
            label: '地址电话',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 260,
          },
          {
            prop: 'zt',
            label: '状态',
            align: 'center',
            width: 80,
            resizable: false,
          },
          {
            prop: 'yezId',
            label: '业主编码',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 120,
          },
          {
            prop: 'yezFlg',
            label: '是否客户资料',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 100,
          },
          {
            prop: 'lianxrPhone',
            label: '联系人电话',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 160,
          },
          {
            prop: 'khZzbm',
            label: 'NC组织编码',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 120,
          },
        ],
        // 表格搜索条件
        where: {},
        // 表格选中数据
        selection: [],
        // 当前编辑数据
        current: null,
        // 是否显示编辑弹窗
        showEdit: false,
        // 是否显示导入弹窗
        showImport: false
      };
    },
    methods: {
      /* 刷新表格 */
      reload() {
        this.$refs.table.reload({where: this.where});
      },
      /* 重置搜索 */
      reset() {
        this.where = {};
        this.reload();
      },
      /* 显示编辑 */
      openEdit(row) {
        this.current = row;
        this.showEdit = true;
      },
      /* 删除 */
      remove(row) {
        const loading = this.$loading({lock: true});
        this.$http.delete('/member/delete/' + [row.id]).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      },
      /* 批量删除 */
      removeBatch() {
        if (!this.selection.length) {
          this.$message.error('请至少选择一条数据')
          return;
        }
        this.$confirm('确定要删除选中的会员吗?', '提示', {
          type: 'warning'
        }).then(() => {
          const loading = this.$loading({lock: true});
          this.$http.delete('/member/delete/' + [this.selection.map(d => d.id)]).then(res => {
            loading.close();
            if (res.data.code === 0) {
              this.$message({type: 'success', message: res.data.msg});
              this.reload();
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            loading.close();
            this.$message.error(e.message);
          });
        }).catch(() => {
        });
      },
      /* 更改状态 */
      editStatus(row) {
        const loading = this.$loading({lock: true});
        let params = Object.assign({
          "id": row.id,
          "status": row.status
        })
        this.$http.put('/member/status', params).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message({type: 'success', message: res.data.msg});
          } else {
            row.status = !row.status ? 1 : 2;
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      }
    }
  }
  </script>

  <style scoped>
  </style>
